* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: #3204fd;
    font-family: Arial, sans-serif; /* Added for better default styling */
}

.controller {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 800px;
    padding: 20px;
    color: white;
    position: relative;
    margin-bottom: 20px; /* Added to give space between controller and game grid */
}

#new-game {
    padding: 5px 10px;
    background-color: #fff;
    color: #fd0404;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#new-game:hover {
    background-color: #f0f0f0;
}

.stats {
    display: flex;
    gap: 20px;
    align-items: center;
}

.memory_game {
    width: 90%;
    max-width: 650px; /* Maximum width for large screens */
    aspect-ratio: 1 / 1; /* Maintain aspect ratio */
    background: black;
    border-radius: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 5px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    margin: 0 auto;
}


.memory_card {
    width: calc(25% - 10px);
    height: calc(25% - 10px);
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.3s ease-out;
    cursor: pointer;
    background-color: #f0f0f0;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.front-face,
.back-face {
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    object-fit: cover;
    backface-visibility: hidden;
    border-radius: 10px;
}

.memory_card:active {
    transform: scale(0.97);
    transition: transform 0.15s ease-out;
}

.front-face {
    transform: rotateY(180deg);
}

.memory_card.flip .front-face {
    transform: rotateY(0deg);
}

.memory_card.flip .back-face {
    transform: rotateY(180deg);
}

#congratulations {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #ffffff;
    border-radius: 10px;
    padding: 20px 40px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
}

#congratulations h1 {
    font-size: 2.5em;
    color: #fd0404;
    margin: 0;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

#congratulations.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1.1);
}

/* Modal Styles */
.modal {
    display: none; 
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7); /* Darker background for better contrast */
    animation: fadeIn 0.5s ease-in-out; /* Fade-in animation */
}

@keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.modal-content {
    background-color: #fefefe;
    margin: 10% auto;
    padding: 30px;
    border: none;
    width: 80%;
    max-width: 600px;
    border-radius: 20px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
    transform: translateY(-20px);
    animation: slideIn 0.5s ease-in-out;
}

@keyframes slideIn {
    0% {
        transform: translateY(-50px);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-btn {
    color: #ff4545; /* Red color for close button */
    float: right;
    font-size: 30px;
    font-weight: bold;
    transition: color 0.3s ease;
}

.close-btn:hover,
.close-btn:focus {
    color: #ff0000;
    text-decoration: none;
    cursor: pointer;
    transform: scale(1.1); /* Slight grow on hover */
}

h2 {
    color: #3204fd; /* Match the background color */
    text-align: center;
    font-size: 2em;
    margin-bottom: 20px;
    animation: textPulse 1s infinite; /* Pulsing effect */
}

@keyframes textPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

p {
    font-size: 1.2em;
    line-height: 1.6;
    color: #333;
    margin-bottom: 15px;
    transition: color 0.3s ease;
}

p:hover {
    color: #fd0404; /* Change color on hover */
}

.modal-content p:nth-child(3),
.modal-content p:nth-child(4),
.modal-content p:nth-child(5) {
    animation: fadeInDelay 0.5s ease-in-out forwards;
}

@keyframes fadeInDelay {
    0% {
        opacity: 0;
        transform: translateY(-10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-content h3 {
    margin-top: 20px;
    color: #fd0404;
    font-size: 1.8em;
    text-align: center;
}

.modal-content p:last-child {
    margin-bottom: 0;
}

/* Button hover effect for the instruction button */
#instruction-btn {
    padding: 10px 15px;
    background-color: #fff;
    color: #3204fd;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.3s ease;
}

#instruction-btn:hover {
    background-color: #f0f0f0;
    transform: scale(1.05); /* Slight grow on hover */
}
